package cn.lyb.config;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

@Aspect
@Slf4j
@Component
public class MyAop {

    @Pointcut("execution(* cn.lyb.service.*.*(..)) && @annotation(AopLog)")
    public void cut() {
    }

    @Before(value = "cut()")
    public void logBefore(JoinPoint joinPoint) {
        log.info("logBefore() is running!");
        MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
        Method method = methodSignature.getMethod();
        log.info("methodName:[{}],annotation:[{}]", method.getName(), method.getAnnotation(AopLog.class).value());
    }

}
